package com.edward.action;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.edward.model.CncaList;
import com.edward.service.CncaListManager;
import com.opensymphony.xwork2.ActionSupport;

public class PrintCncaListAction extends ActionSupport{
	

	private static final long serialVersionUID = 7000562419610510545L;

	private List<String>list;
	
	private Map<String,Object> map;
	
	private CncaListManager cncaListManager;
	
	private CncaList cncaList;

	public CncaList getCncaList() {
		return cncaList;
	}

	public void setCncaList(CncaList cncaList) {
		this.cncaList = cncaList;
	}

	public void setCncaListManager(CncaListManager cncaListManager) {
		this.cncaListManager = cncaListManager;
	}
	
	public List<String> getList() {
		return list;
	}
	
	public void setList(List<String> list) {
		this.list = list;
	}
	
	public Map<String, Object> getMap() {
	        return map;
	    }
	
    public void setMap(Map<String, Object> map) {
	        this.map = map;
	    }

	public String execute() throws Exception {
		CncaList c = cncaListManager.getCncaList(cncaList.getId());
		list = Arrays.asList(new String[]{"1"});
		map = testReflect(c);
		return SUCCESS;
	}
	
	 public static Map<String,Object> testReflect(Object obj) {      
		  Map<String,Object> hashMap = new HashMap<String,Object>();      
		  try {      
		   Class<? extends Object> c = obj.getClass();      
		   Method m[] = c.getDeclaredMethods();      
		   for (int i = 0; i < m.length; i++) {  
			   //判断目前的方法是否以get开始
			   if (m[i].getName().indexOf("get")==0) {      
				   hashMap.put(m[i].getName(), m[i].invoke(obj, new Object[0]));      
		    }      
		   }      
		  } catch (Throwable e) {      
		   System.err.println(e);      
		  }      
		  return hashMap;      
		 }   


}
